﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Linq;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Kaesoft.Hospedaje.Common;
using System.Collections.ObjectModel;
using Kaesoft.Hospedaje.Entities;
using Kaesoft.Hospedaje.Proxy;

namespace Kaesoft.Hospedaje.DatosReglasViews
{
    public class ServiciosViewModel : ViewModelBase
    {
        private ObservableCollection<ApplicationInfo> _serviciosHospedaje = GenerateApplicationInfos();
        private BarraTareasViewModel _barraTareasViewModel;

        public BarraTareasViewModel BarraTareasViewModel
        {
            get { return _barraTareasViewModel; }
            set
            {
                if (_barraTareasViewModel != value)
                {
                    _barraTareasViewModel = value;
                    OnPropertyChanged("BarraTareasViewModel");
                }
            }
        }

        public ObservableCollection<ApplicationInfo> ServiciosHospedaje
        {
            get
            {
                return _serviciosHospedaje;
            }
            set
            {
                if (_serviciosHospedaje != value)
                {
                    _serviciosHospedaje = value;
                    OnPropertyChanged("ServiciosHospedaje");
                }
            }
        }

        private void HabilitarBotones()
        {
            BarraTareasViewModel = new BarraTareasViewModel();
            BarraTareasViewModel.IsEnableGuardar = true;
            BarraTareasViewModel.IsVisibleGuardar = true;
            BarraTareasViewModel.IsVisibleNuevo = true;
            BarraTareasViewModel.IsEnableNuevo = true;
            BarraTareasViewModel.IsVisibleCancelar = true;
            BarraTareasViewModel.IsEnableCancelar = true;
            BarraTareasViewModel.IsVisibleEditar = true;
            BarraTareasViewModel.IsEnableEditar = true;
        }

        public ServiciosViewModel()
        {
            HabilitarBotones();
            BarraTareasViewModel.BotonTareaClick += BotonOperacionClick;
        }

        private void BotonOperacionClick(object sender, EventArgs<string> e)
        {
            switch (e.Data.ToString())
            {
                case "Nuevo":
                    var al = "1";
                    break;
                case "Editar":
                    var al0 = "1";
                    break;
                case "Cancelar":
                    var al1 = "1";
                    break;
                case "Guardar":
                    var al2 = "1";
                    break;
                default:
                    break;
            }
        }

        public static ObservableCollection<ApplicationInfo> GenerateApplicationInfos()
        {
            var result = new List<Servicio>();
            var resultado = new ObservableCollection<ApplicationInfo>();
            ProxyDatosReglas.ObtenerServiciosAsync((s) =>
                {
                    if (s.Error != null)
                        return;
                    result = s.Result;
                    result.ForEach(a => resultado.Add(new ApplicationInfo() { Id = a.idServicio, Creador = "Costo: " + a.valor.Value.ToString("C", CultureInfo.CurrentCulture), Icono = a.imagen, Nombre = a.nombre, Precio = Convert.ToDouble(a.valor.Value) }));
                }
            );
            return resultado;
        }

        public static ObservableCollection<ApplicationInfo> GenerateMyApplicationInfos()
        {
            var result = new ObservableCollection<ApplicationInfo>();
            return result;
        }

    }
}
